package com.zxcl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxcl.domain.HotSearch;
import com.zxcl.dto.HotSearchQueryDTO;
import com.zxcl.dto.PageDTO;
import com.zxcl.model.Result;
import com.zxcl.service.HotSearchService;
import com.zxcl.utils.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述: [热搜管理]
 * 作者: zxcl
 */
@RestController
@Api(tags = "热搜管理")
@RequestMapping("admin/hotSearch")
public class HotSearchController {

    @Autowired
    private HotSearchService hotSearchService;


    @GetMapping("page")
    @ApiOperation("分页查询热搜")
    @PreAuthorize("hasAuthority('admin:hotSearch:page')")
    public Result<Page<HotSearch>> loadHotSearchPage(PageDTO pageDTO, HotSearchQueryDTO hotSearch) {
        Page<HotSearch> hotSearchPage = hotSearchService.loadHotSearchPage(pageDTO, hotSearch);
        return Result.success(hotSearchPage);
    }


    @PostMapping
    @ApiOperation("新增热搜")
    @PreAuthorize("hasAuthority('admin:hotSearch:save')")
    public Result<String> addHotSearch(@RequestBody HotSearch hotSearch) {
        int i = hotSearchService.addHotSearch(hotSearch);
        return Result.handle(i > 0);
    }

    @GetMapping("hotSearchByShopId")
    @ApiOperation("搜索店铺热门商品")
    public Result<List<HotSearch>> hotSearchMall(Integer number, Long shopId, Integer sort){
        List<HotSearch> hotSearchPage = hotSearchService.hotSearchMall(number,shopId,sort);
        return Result.success(hotSearchPage);
    }
}
